# backend/models/base_model.py
"""
基础模型抽象类
"""

from abc import ABC, abstractmethod
from typing import AsyncGenerator, Dict, Any, Optional
from langchain.schema import BaseMessage
from pydantic import BaseModel

class AIModelResponse(BaseModel):
    """AI模型响应数据模型"""
    content: str
    model_name: str
    provider: str
    metadata: Dict[str, Any] = {}
    usage_stats: Optional[Dict[str, int]] = None

class BaseAIModel(ABC):
    """AI模型基类"""
    
    def __init__(self, model_name: str, api_key: str = ""):
        self.model_name = model_name
        self.api_key = api_key
        self.provider = self.get_provider_name()
        self.llm = None
    
    @abstractmethod
    def get_provider_name(self) -> str:
        """获取提供商名称"""
        pass
    
    @abstractmethod
    async def initialize(self) -> None:
        """初始化模型"""
        pass
    
    @abstractmethod
    async def generate_response(
        self, 
        messages: list[BaseMessage],
        **kwargs
    ) -> AIModelResponse:
        """生成响应"""
        pass
    
    @abstractmethod
    async def stream_response(
        self, 
        messages: list[BaseMessage],
        **kwargs
    ) -> AsyncGenerator[str, None]:
        """流式生成响应"""
        pass

